﻿using LoggingMagic.AssemlyOperations;

namespace LoggingMagic
{
    internal class Processor
    {
        private readonly ProcessedLabel _processedLabel;
        private readonly MethodFinder _methodFinder;
        private readonly MethodProcessor _methodProcessor;



        public Processor(ProcessedLabel processedLabel, MethodFinder methodFinder, MethodProcessor methodProcessor)
        {
            _processedLabel = processedLabel;
            _methodFinder = methodFinder;
            _methodProcessor = methodProcessor;
        }

        /// <summary>
        /// Processes module
        /// </summary>
        /// <returns>Returns null is module is already processed.
        /// Returns true is some properties are transformed, false otherwise.
        /// </returns>
        public bool? Process()
        {
            if (!_processedLabel.NeedProcessing)
                return null;

            var methods = _methodFinder.FindMethods();

            if (methods == null) return null;

            int processed = 0;
            foreach (var method in methods)
            {
                _methodProcessor.ProcessMethod(method);
                processed++;
            }

            _processedLabel.MarkAsProcessed();

            return processed > 0;
        }
    }
}